//
//  HeTongDetailVC.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/3.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "AddHeTongDetailVC.h"
#import "BaoJiaBillVC.h"

@interface AddHeTongDetailVC ()

@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) HeTongMainModel *model;

@end

@implementation AddHeTongDetailVC

-(HeTongMainModel *)model {
    if (!_model) {
        _model = [HeTongMainModel new];
    }
    return _model;
}

-(UIView *)bottomView {
    if (!_bottomView) {
        _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenH - BottomHeight - NaviHeight - 64, ScreenW, 64+BottomHeight)];
        _bottomView.backgroundColor = HexColor(0xffffff);
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(30, 10, _bottomView.nim_width - 60, 44)];
        bgView.backgroundColor = Color_ThemeColor;
        bgView.layer.masksToBounds = YES;
        bgView.layer.cornerRadius = 6;
        [_bottomView addSubview:bgView];
        
        UIImageView *arrowImgView = [UIImageView new];
        [arrowImgView setImage:[UIImage imageNamed:@"icon_selection_sel"]];
        [bgView addSubview:arrowImgView];
        
        UILabel *arrowLab = [UILabel new];
        arrowLab.textColor = HexColor(0xffffff);
        arrowLab.font = BoldFontOfSize(16);
        arrowLab.text = @"选择合同";
        [bgView addSubview:arrowLab];
        [arrowLab sizeToFit];
        arrowImgView.nim_width = 18;
        arrowImgView.nim_height = 18;
        arrowImgView.nim_left = (bgView.nim_width - 10 - arrowImgView.nim_width - arrowLab.nim_width) * 0.5;
        arrowImgView.nim_centerY = bgView.nim_height * 0.5;
        
        arrowLab.nim_left = arrowImgView.nim_right + 10;
        arrowLab.nim_centerY = arrowImgView.nim_centerY;
        
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, bgView.nim_width, bgView.nim_height)];
        [btn addTarget:self action:@selector(chooseClick) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:btn];
    }
    return _bottomView;
}

- (void)chooseClick {
    if (self.selectBlock) {
        self.selectBlock();
        [self.rt_navigationController popViewControllerAnimated:YES];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"合同详情";
    [self.view addSubview:self.bottomView];
    [self requestForData];
}

- (void)requestForData {
    [HttpRequest GetWithApi:ReceiptDeliveryHeTongDetail params:@{@"co_id":self.co_id} progress:^(NSProgress * _Nonnull progress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull operation, id  _Nonnull responseObject, BOOL code, NSInteger errorCode) {
        if (code) {
            self.model = [HeTongMainModel mj_objectWithKeyValues:responseObject];
            [self configUI];
        }
    } fail:^(NSError * _Nonnull error) {
        
    }];
}

- (void)configUI {
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 10, ScreenW - 30, 200)];
    bgView.backgroundColor = HexColor(0xffffff);
    bgView.layer.masksToBounds = YES;
    bgView.layer.cornerRadius = 6;
    [self.view addSubview:bgView];
    
    UILabel *noTitleLab = [UILabel new];
    noTitleLab.textColor = HexColor(0x9C9DB3);
    noTitleLab.font = [UIFont systemFontOfSize:14];
    noTitleLab.text = @"合同流水号：";
    [bgView addSubview:noTitleLab];
    [noTitleLab sizeToFit];
    CGFloat margin = (bgView.nim_height - 5 * noTitleLab.nim_height) * 0.16666666;
    noTitleLab.nim_top = margin;
    noTitleLab.nim_left = 15;
    
    UIButton *fuZhiBtn = [UIButton new];
    [fuZhiBtn setImage:[UIImage imageNamed:@"icon_ladingbill_erweima"] forState:0];
    fuZhiBtn.nim_width = 18;
    fuZhiBtn.nim_height = 18;
    fuZhiBtn.nim_left = bgView.nim_width - 15 - fuZhiBtn.nim_width;
    fuZhiBtn.nim_centerY = noTitleLab.nim_centerY;
    [fuZhiBtn addTarget:self action:@selector(fuZhiClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:fuZhiBtn];
    
    UILabel *noLab = [[UILabel alloc] initWithFrame:CGRectMake(noTitleLab.nim_right + 10, noTitleLab.nim_top, fuZhiBtn.nim_left - (noTitleLab.nim_right + 10), noTitleLab.nim_height)];
    noLab.textColor = HexColor(0x2B2C44);
    noLab.font = BoldFontOfSize(14);
    noLab.textAlignment = NSTextAlignmentRight;
    noLab.text = self.model.constract_sn;
    [bgView addSubview:noLab];
    
    UILabel *companyTitleLab = [UILabel new];
    companyTitleLab.textColor = HexColor(0x9C9DB3);
    companyTitleLab.font = [UIFont systemFontOfSize:14];
    companyTitleLab.text = @"承运方：";
    [bgView addSubview:companyTitleLab];
    [companyTitleLab sizeToFit];
    companyTitleLab.nim_left = noTitleLab.nim_left;
    companyTitleLab.nim_top = noTitleLab.nim_bottom + margin;
    
    UILabel *companyLab = [[UILabel alloc] initWithFrame:CGRectMake(companyTitleLab.nim_right + 10, companyTitleLab.nim_top, bgView.nim_width - 15 - (companyTitleLab.nim_right + 10), companyTitleLab.nim_height)];
    companyLab.textColor = HexColor(0x2B2C44);
    companyLab.font = BoldFontOfSize(14);
    companyLab.textAlignment = NSTextAlignmentRight;
    companyLab.text = self.model.name;
    [bgView addSubview:companyLab];
    
    UILabel *dateTitleLab = [UILabel new];
    dateTitleLab.textColor = HexColor(0x9C9DB3);
    dateTitleLab.font = [UIFont systemFontOfSize:14];
    dateTitleLab.text = @"合同有效期：";
    [bgView addSubview:dateTitleLab];
    [dateTitleLab sizeToFit];
    dateTitleLab.nim_left = noTitleLab.nim_left;
    dateTitleLab.nim_top = companyTitleLab.nim_bottom + margin;
    
    UILabel *dateLab = [[UILabel alloc] initWithFrame:CGRectMake(dateTitleLab.nim_right + 10, dateTitleLab.nim_top, bgView.nim_width - 15 - (dateTitleLab.nim_right + 10), dateTitleLab.nim_height)];
    dateLab.textColor = HexColor(0x2B2C44);
    dateLab.font = BoldFontOfSize(14);
    dateLab.textAlignment = NSTextAlignmentRight;
    dateLab.text = [NSString stringWithFormat:@"%@ - %@",self.model.startTime,self.model.endTime];
    [bgView addSubview:dateLab];
    
    UILabel *dayTitleLab = [UILabel new];
    dayTitleLab.textColor = HexColor(0x9C9DB3);
    dayTitleLab.font = [UIFont systemFontOfSize:14];
    dayTitleLab.text = @"对账周期（天）：";
    [bgView addSubview:dayTitleLab];
    [dayTitleLab sizeToFit];
    dayTitleLab.nim_left = noTitleLab.nim_left;
    dayTitleLab.nim_top = dateTitleLab.nim_bottom + margin;
    
    UILabel *dayLab = [[UILabel alloc] initWithFrame:CGRectMake(dayTitleLab.nim_right + 10, dayTitleLab.nim_top, bgView.nim_width - 15 - (dayTitleLab.nim_right + 10), dayTitleLab.nim_height)];
    dayLab.textColor = HexColor(0x2B2C44);
    dayLab.font = BoldFontOfSize(14);
    dayLab.textAlignment = NSTextAlignmentRight;
    dayLab.text = self.model.cycle;
    [bgView addSubview:dayLab];
    
    UILabel *styleTitleLab = [UILabel new];
    styleTitleLab.textColor = HexColor(0x9C9DB3);
    styleTitleLab.font = [UIFont systemFontOfSize:14];
    styleTitleLab.text = @"结算方式：";
    [bgView addSubview:styleTitleLab];
    [styleTitleLab sizeToFit];
    styleTitleLab.nim_left = noTitleLab.nim_left;
    styleTitleLab.nim_top = dayTitleLab.nim_bottom + margin;
    
    UILabel *styleLab = [[UILabel alloc] initWithFrame:CGRectMake(styleTitleLab.nim_right + 10, styleTitleLab.nim_top, bgView.nim_width - 15 - (styleTitleLab.nim_right + 10), styleTitleLab.nim_height)];
    styleLab.textColor = HexColor(0x2B2C44);
    styleLab.font = BoldFontOfSize(14);
    styleLab.textAlignment = NSTextAlignmentRight;
    styleLab.text = self.model.type;
    [bgView addSubview:styleLab];
    
    UIButton *listBtn = [[UIButton alloc] initWithFrame:CGRectMake(bgView.nim_left, bgView.nim_bottom + 10, bgView.nim_width, 50)];
    listBtn.backgroundColor = HexColor(0xffffff);
    listBtn.layer.masksToBounds = YES;
    listBtn.layer.cornerRadius = 6;
    [listBtn setTitle:@"查看报价单" forState:0];
    [listBtn setTitleColor:Color_ThemeColor forState:0];
    listBtn.titleLabel.font = BoldFontOfSize(16);
    [listBtn setImage:[UIImage imageNamed:@"icon_form"] forState:0];
    [listBtn addTarget:self action:@selector(lookClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:listBtn];
}

- (void)lookClick {
    BaoJiaBillVC *vc = [BaoJiaBillVC new];
    vc.q_id = self.model.q_id;
    [self.rt_navigationController pushViewController:vc animated:YES];
}

- (void)fuZhiClick {
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
